import {
	defineStore
} from "pinia";
import {
	computed,
	onMounted,
	ref
} from "vue";

export const useUserStore = defineStore(
	"user",
	() => {
		const token = ref();
		const backUrl = "http://127.0.0.1:9091" //import.meta.env.VITE_BASE_URL;
		const useInfo = ref({});
		const isAdmin = ref(false);
		const systemConfig = ref({
			roles: [],
			systemName: "",
			systemLoginBack: "",
			systemRegisterBack: "",
			systemTableBack: "",
			changePassword: false,
		})

		function setSystemConfig(data) {
			systemConfig.value = data;
		}

		function setIsAdmin(data) {
			isAdmin.value = data;
		}

		function getIsAdmin() {
			return isAdmin.value;
		}


		function getSystemConfig() {
			return systemConfig.value;
		}

		function getBackUrl() {
			return backUrl;
		}

		function getUserInfo() {
			return useInfo.value;
		}

		function setUserInfo(data) {
			useInfo.value = data;
		}

		function setToken(tokenResult) {
			token.value = tokenResult;
		}

		function getToken() {
			return token.value;
		}

		function clear() {
			useInfo.value = {};
			token.value = "";
		}

		return {
			setSystemConfig,
			getSystemConfig,
			getBackUrl,
			useInfo,
			token,
			setIsAdmin,
			getIsAdmin,
			getUserInfo,
			setUserInfo,
			getToken,
			setToken,
			clear,
		};
	}, {
		persist: {
			storage: sessionStorage,
		},
	},
);
